<template>
  <div class="login-wrap">
    <div class="ms-login">
      <div class="ms_loginis">
        <div class="ms-title">用户登录</div>
        <!--model为表单数据 rules为表单规则-->
        <el-form
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm"
            label-width="0px"
            class="ms-content"
        >
          <el-form-item prop="mobile">
            <el-input
                v-model="ruleForm.mobile"
                placeholder="请输入用户名"
            ></el-input>
          </el-form-item>
          <el-form-item prop="password">
            <el-input
                type="password"
                v-model="ruleForm.password"
                placeholder="请输入密码"
                @keyup.enter.native="submitForm('ruleForm')"
            ></el-input>
          </el-form-item>
          <p class="login-tips">Tips : 请不要把用户名轻易泄露给他人！</p>
          <div class="login-btn">
            <el-button
                type="primary"
                :loading="loading"
                color="47A29A"
                @click="submitForm('ruleForm')"
            >登 录
            </el-button
            >
          </div>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data: function () {
    return {
      ruleForm: {
        mobile: "admin",
        password: "admin",
      },
      rules: {
        mobile: [{required: true, message: "请输入用户名", trigger: "blur"}],
        password: [{required: true, message: "请输入密码", trigger: "blur"}],
      },
      loading: false,
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$axios
              .peisLogin({
                userName: this.ruleForm.mobile,
                psw: this.ruleForm.password,
              })
              .then((res) => {
                if (res.code === "00000") {
                  localStorage.setItem("Xdh_token", res.data.token);

                  let arr = [];
                  /* 临时 */
                  console.log(JSON.stringify(res.data.ch[0].ch[1]))
                  var en = {
                    menuId: 'd4e68e50-53de-4ee6-9826-e1614fbd827b',
                    menuName: "团检分组",
                    parentId: "90482c4f-947f-4031-9c23-efb5525f38d6",
                    index: "/basic/contractGroup",
                    icon: null,
                    ch: []
                  }
                  var en2 = {
                    menuId: 'd4e68e50-53de-4ee6-9826-e1614fbd827b',
                    menuName: "用户授权",
                    parentId: "35ca62ab-0485-4f74-aa15-aa5e930f9bcc",
                    index: "/system/useraccess",
                    icon: null,
                    ch: []
                  }
                  var en3 = {
                    menuId: 'd4e68e50-53de-4ee6-9826-e1614fbd827b',
                    menuName: "合同封闭",
                    parentId: "820d6b01-140e-4013-b9a0-5df4d4689240",
                    index: "/front/contractclose",
                    icon: null,
                    ch: []
                  }
                  var en4 = {
                    menuId: 'd4e68e50-53de-4ee6-9826-e1614fbd827b',
                    menuName: "报告管理",
                    parentId: "820d6b01-140e-4013-b9a0-5df4d4689240",
                    index: "/physicalcenter/reportchange",
                    icon: null,
                    ch: []
                  }
                  var en5 = {
                    menuId: 'd4e68e50-53de-4ee6-9826-e1614fbd827b',
                    menuName: "收表查询",
                    parentId: "820d6b01-140e-4013-b9a0-5df4d4689240",
                    index: "/visitphysician/confirmList",
                    icon: null,
                    ch: []
                  }
                  var en6 = {
                    menuId: 'd4e68e50-53de-4ee6-9826-e1614fbd827b',
                    menuName: "密码修改",
                    parentId: "820d6b01-140e-4013-b9a0-5df4d4689240",
                    index: '/system/password',
                    icon: null,
                    ch: []
                  }
                  var en8 = {
                    menuId: 'd4e68e50-53de-4ee6-9826-e1614fbd827b',
                    menuName: "全局变量",
                    parentId: "820d6b01-140e-4013-b9a0-5df4d4689240",
                    index: '/system/config',
                    icon: null,
                    ch: []
                  }
                  var en7 = {
                    menuId: 'd4e68e50-53de-4ee6-9826-e1614fbd827b',
                    menuName: "集中打印",
                    parentId: "820d6b01-140e-4013-b9a0-5df4d4689240",
                    index: '/front/print',
                    icon: null,
                    ch: []
                  }

                  /* 临时 */
                  // res.data.ch[5].ch[2] = en2;
                  // res.data.ch[2].ch[7] = en3;
                  // res.data.ch[2].ch[8] = en4;
                  // res.data.ch[3].ch[1] = en5;
                  // res.data.ch[4].ch[9] = en;
                  // res.data.ch[5].ch[3] = en6;
                  // res.data.ch[5].ch[4] = en8;
                  // res.data.ch[1].ch[3] = en7;
                  arr = res.data.ch;
                  sessionStorage.setItem("me_u", JSON.stringify(arr)); //保存用户ID
                  localStorage.setItem(
                      "ms_u",
                      JSON.stringify({
                        //保存用户信息
                        name: res.data.personName,
                        username: res.data.userName,
                      })
                  );
                  localStorage.setItem("ms_userInfo",JSON.stringify(res.data))
                  this.$router.push({name: "homes"});
                }
              });
        }
      });

      // this.loading = true;
      //提交表单
      // this.$axios
      //   .login({
      //     ...this.ruleForm,
      //   })
      //   .then((res) => {
      // this.loading = false;
      // this.$router.push({name:'home'});

      //   // 保存菜单
      //   sessionStorage.setItem("me_u", JSON.stringify(res.data.menu));
      //   sessionStorage.setItem("token", res.data.token);
      //   //判断菜单第一个元素是否有二级页面
      //   const href =
      //     res.data.menu[0].pid != 0
      //       ? res.data.menu[0].index
      //       : res.data.menu[0].ch[0].index;
      //   console.log(href);
      //   this.$router.push({ name: href }); //跳转
      //   this.loading = false;
      // }
      // });
    },
  },
};
</script>

<style scoped>
.login-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  /* background: url("../assets/img/tu.png") no-repeat; */
  background: #d1e5e1;
  background-size: 100% 100%;
}

.el-form-item {
  /* width: 75%; */
  margin: 0 64px 24px;
}

.el-form-item:nth-child(2) {
  margin-bottom: 10px;
}

.ms-title {
  margin-top: 10%;
  width: 100%;
  text-align: center;
  font-size: 26px;
  font-weight: 500;
  text-align: center;
  color: #333333;
  line-height: 37px;
  border-bottom: 1px solid #fafefa;
}

.ms-login {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 808px;
  transform: translate(-50%, -50%);
  height: 479px;
  /* margin: -190px 0 0 -175px; */
  border-radius: 5px;
  background: rgba(255, 255, 255);
  overflow: hidden;
}
.ms_loginis {
  width: 600px;
  margin: 0px auto;
}

.ms-content {
  padding: 30px 0 0;
}

.login-btn {
  text-align: center;
  margin: 82px 64px 64px;
}

.login-btn button {
  width: 100%;
  height: 50px;
  /* margin-bottom: 10px; */
  border-radius: 4px;
  padding: 0;
  font-size: 24px;
}

.login-tips {
  font-size: 12px;
  line-height: 30px;
  color: #979797;
  margin-left: 64px;
}

.el-button--primary {
  border: none;
  background: #0a93fd;
}

/* /deep/ .el-input__inner{
	height: 56px;
} */
</style>
